<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">
				<el-form-item label="分销商" prop="useruuid">
					<el-select v-model="filters.useruuid" placeholder="请选择分销商" v-show="isShow"  clearable  filterable >
						<el-option value="0" label="全部">全部</el-option>
						<el-option
								v-for="item in users"
								:key="item.user.useruuid"
								:label="item.user.username"
								:value="item.user.useruuid">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item>
					<el-date-picker type="date" placeholder="开始时间" format="yyyy-MM-dd" clearable v-model="filters.starttime"
									style="width: 100%;"></el-date-picker>
				</el-form-item>
				<el-form-item>
					<el-date-picker type="date" placeholder="结束时间" format="yyyy-MM-dd" clearable v-model="filters.endtime"
									style="width: 100%;"></el-date-picker>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" v-on:click="findDownProductLog">查询</el-button>
				</el-form-item>
			</el-form>
		</el-col>

		<!--列表-->
		<el-table :data="pros" highlight-current-row v-loading="listLoading" border  max-height="620" style="width: 100%;">
			<el-table-column type="index" width="80" label="编号">
			</el-table-column>
			<el-table-column prop="userLog.username" label="操作人" show-overflow-tooltip  >
			</el-table-column>
			<el-table-column prop="downShopProduct.user.username" label="分销商名称" show-overflow-tooltip   >
			</el-table-column>
			<el-table-column prop="downShopProduct.productName" label="产品名称"  show-overflow-tooltip  >
			</el-table-column>
			<el-table-column prop="downShopProduct.downprouuid" label="产品编码" show-overflow-tooltip width="200px"   >
			</el-table-column>
			<el-table-column prop="downShopProduct.downfacevalue" label="面值"  show-overflow-tooltip  >
			</el-table-column>
			<el-table-column prop="downShopProduct.discount" label="折扣" show-overflow-tooltip   >
			</el-table-column>
			<el-table-column prop="downShopProduct.discountAmount" label="成本金额" show-overflow-tooltip  >
			</el-table-column>
			<el-table-column prop="operationtarget" label="操作类型"  show-overflow-tooltip >
			</el-table-column>
			<el-table-column prop="createtime" label="更改时间" width="190" show-overflow-tooltip  >
			</el-table-column>
			<el-table-column prop="remark" label="备注" min-width="180" show-overflow-tooltip   >
			</el-table-column>
		</el-table>

		<!--工具条-->
		<el-pagination
				@current-change="handleCurrentChange"
				@size-change="handleSizeChange"
				layout="total,sizes,prev, pager, next"
				:total="total">
		</el-pagination>


	</section>
</template>

<script>
    import util from '../../common/js/util'
    //import NProgress from 'nprogress'
    import { findDownProductLog,findAllDownShopInfo} from '../../api/api';
	import moment from 'moment';

    export default {
        data() {
            return {
                filters: {
                    useruuid: '',
					starttime: moment(new Date(),"YYYY-MM-DD HH:mm:ss").format('YYYY-MM-DD') + " 00:00:00",
					endtime:''
                },
                users: [],
                total: 0,
                start:0,
                isShow: JSON.parse(sessionStorage.getItem("user")).usertype === 1 ? true : JSON.parse(sessionStorage.getItem("user")).usertype === 2 ? true : false,
                pageSize: 10,
                listLoading: false,
                pros: [],
            }
        },
        methods: {
            //性别显示转换
            formatSex: function (row, column) {
                return row.sex == 1 ? '男' : row.sex == 0 ? '女' : '未知';
            },
            handleCurrentChange: function (val) {
                this.start = val - 1;
                this.findDownProductLog();
            },
            handleSizeChange: function (val) {
                this.pageSize = val;
                this.findDownProductLog();
            },
            findDownProductLog() {
				let para = {
					start: this.start,
					pageSize: this.pageSize,
					useruuid:this.filters.useruuid == "0" ? "": this.filters.useruuid,
					starttime: this.filters.starttime = (!this.filters.starttime || this.filters.starttime == '') ? '' : util.formatDate.format(new Date(this.filters.starttime), 'yyyy-MM-dd'),
					endtime: this.filters.endtime = (!this.filters.endtime || this.filters.endtime == '') ? '' : util.formatDate.format(new Date(this.filters.endtime), 'yyyy-MM-dd'),
				};
                this.listLoading = true;
                //NProgress.start();
                findDownProductLog(para).then((datas) => {
                    let {message, code, data} = datas;
					if (code !== "0") {
						this.$message({
							message: message,
							type: 'error'
						});
					} else {
						this.pros = data.result;
						this.total = data.totalCount;
					}
						this.listLoading = false;
				});
            },findAllDownShopInfo:function(){
            let para = {useruuid: JSON.parse(sessionStorage.getItem("user")).useruuid};
            findAllDownShopInfo(para).then(datas => {
                let {message, code, data} = datas;
                if (code !== "0") {
                    this.$message({
                        message: message,
                        type: 'error'
                    });
                } else {
                    this.users = data;
                }
            });
        },

    },
        mounted() {
            this.findAllDownShopInfo();
            this.findDownProductLog();
        }
    }

</script>

<style scoped>

</style>
